<html xmlns:fb="http://ogp.me/ns/fb#">
	<head>
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
		<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
	</head>
	</body>
		<div id="fb-root"></div>
		<script>(function(d, s, id) {
		  var js, fjs = d.getElementsByTagName(s)[0];
		  if (d.getElementById(id)) return;
		  js = d.createElement(s); js.id = id;
		  js.src = "//connect.facebook.net/es_ES/all.js#xfbml=1";
		  fjs.parentNode.insertBefore(js, fjs);
		}(document, 'script', 'facebook-jssdk'));
		</script>
		<div class="movies view">
		<h2><?php  echo __('Movie');?></h2>
			<dl>
				<dt><?php echo __('Id'); ?></dt>
				<dd>
					<?php echo h($movie['Movie']['id']); ?>
					&nbsp;
				</dd>
				<dt><?php echo __('Title'); ?></dt>
				<dd>
					<?php echo h($movie['Movie']['title']); ?>
					&nbsp;
				</dd>
				<dt><?php echo __('Plot'); ?></dt>
				<dd>
					<?php echo h($movie['Movie']['plot']); ?>
					&nbsp;
				</dd>
				<dt><?php echo __('Release Date'); ?></dt>
				<dd>
					<?php 
					App::uses('CakeTime', 'Utility');
					echo CakeTime::format('F jS, Y', $movie['Movie']['release_date']);
					//echo h($movie['Movie']['release_date']); ?>
					&nbsp;
				</dd>
				<dt><?php echo __('Duration'); ?></dt>
				<dd>
					<?php echo h($movie['Movie']['duration']).' min'; ?>
					&nbsp;
				</dd>
				<dt><?php echo __('Rating'); ?></dt>
				<dd>
					<?php echo h($movie['Movie']['rating']); ?>
					&nbsp;
				</dd>
			</dl>
		
			<?php $ref= $this->Html->url( null, true );?>
			<div id=\"like\"><fb:like href=<?php echo $ref; ?> send=\"false\" width=\"450\" show_faces=\"false\"></fb:like></div>
			<div class="fb-comments" data-href=<?php echo $ref; ?> data-num-posts="2" data-width="470"></div>
		</div>
		<div class="actions">
			<h3><?php echo __('Actions'); ?></h3>
			<ul>
				<li><?php echo $this->Html->link(__('Edit Movie'), array('action' => 'edit', $movie['Movie']['id'])); ?> </li>
				<li><?php echo $this->Form->postLink(__('Delete Movie'), array('action' => 'delete', $movie['Movie']['id']), null, __('Are you sure you want to delete # %s?', $movie['Movie']['id'])); ?> </li>
				<li><?php echo $this->Html->link(__('List Movies'), array('action' => 'index')); ?> </li>
				<li><?php echo $this->Html->link(__('New Movie'), array('action' => 'add')); ?> </li>
				<li><?php echo $this->Html->link(__('List Actors'), array('controller' => 'actors', 'action' => 'index')); ?> </li>
				<li><?php echo $this->Html->link(__('New Actor'), array('controller' => 'actors', 'action' => 'add')); ?> </li>
				<li><?php echo $this->Html->link(__('List Directors'), array('controller' => 'directors', 'action' => 'index')); ?> </li>
				<li><?php echo $this->Html->link(__('New Director'), array('controller' => 'directors', 'action' => 'add')); ?> </li>
				<li><?php echo $this->Html->link(__('List Keywords'), array('controller' => 'keywords', 'action' => 'index')); ?> </li>
				<li><?php echo $this->Html->link(__('New Keyword'), array('controller' => 'keywords', 'action' => 'add')); ?> </li>
			</ul>
		</div>
		<div class="related">
			
			<h3><?php echo __('Related Actors');?></h3>
			<?php if (!empty($movie['Actor'])):?>
			<table cellpadding = "0" cellspacing = "0">
			<tr>
				<th><?php echo __('Id'); ?></th>
				<th><?php echo __('Name'); ?></th>
				<th class="actions"><?php echo __('Actions');?></th>
			</tr>
			
			<?php
				$i = 0;
				foreach ($movie['Actor'] as $actor): ?>
				<tr>
					<td><?php echo $actor['id'];?></td>
					<td><?php echo $actor['name'];?></td>
					<td class="actions">
						<?php echo $this->Html->link(__('View'), array('controller' => 'actors', 'action' => 'view', $actor['id'])); ?>
						<?php echo $this->Html->link(__('Edit'), array('controller' => 'actors', 'action' => 'edit', $actor['id'])); ?>
						<?php echo $this->Form->postLink(__('Delete'), array('controller' => 'actors', 'action' => 'delete', $actor['id']), null, __('Are you sure you want to delete # %s?', $actor['id'])); ?>
					</td>
				</tr>
			<?php endforeach; ?>
			</table>
		<?php endif; ?>
		</div>
		<div class="related">
			<h3><?php echo __('Related Directors');?></h3>
			<?php if (!empty($movie['Director'])):?>
			<table cellpadding = "0" cellspacing = "0">
			<tr>
				<th><?php echo __('Id'); ?></th>
				<th><?php echo __('Name'); ?></th>
				<th class="actions"><?php echo __('Actions');?></th>
			</tr>
			<?php
				$i = 0;
				foreach ($movie['Director'] as $director): ?>
				<tr>
					<td><?php echo $director['id'];?></td>
					<td><?php echo $director['name'];?></td>
					<td class="actions">
						<?php echo $this->Html->link(__('View'), array('controller' => 'directors', 'action' => 'view', $director['id'])); ?>
						<?php echo $this->Html->link(__('Edit'), array('controller' => 'directors', 'action' => 'edit', $director['id'])); ?>
						<?php echo $this->Form->postLink(__('Delete'), array('controller' => 'directors', 'action' => 'delete', $director['id']), null, __('Are you sure you want to delete # %s?', $director['id'])); ?>
					</td>
				</tr>
			<?php endforeach; ?>
			</table>
		<?php endif; ?>
		</div>
		<div class="related">
			<h3><?php echo __('Related Movies');?></h3>	
			<?php if (!empty($movie['Movies'])):?>
			<table cellpadding = "0" cellspacing = "0">
			<tr>
				<th><?php echo __('Title'); ?></th>
				<th><?php echo __('Duration'); ?></th>
				<th class="actions"><?php echo __('Actions');?></th>
			</tr>
			<?php
				$i = 0;
				foreach ($movie['Movies'] as $relatedMovie): ?>
				<tr>
					<td><?php echo $relatedMovie['title'];?></td>
					<td><?php echo $relatedMovie['duration'];?></td>
					<td class="actions">
						<?php echo $this->Html->link(__('View'), array('controller' => 'movies', 'action' => 'view', $relatedMovie['id'])); ?>
						<?php echo $this->Html->link(__('Edit'), array('controller' => 'movies', 'action' => 'edit', $relatedMovie['id'])); ?>
						<?php echo $this->Form->postLink(__('Delete'), array('controller' => 'actors', 'action' => 'delete', $relatedMovie['id']), null, __('Are you sure you want to delete # %s?', $relatedMovie['id'])); ?>
					</td>
				</tr>
			<?php endforeach; ?>
			</table>
		<?php endif; ?>
		</div>
		<div class="related">
			<h3><?php echo __('Related Movies from Keywords');?></h3>
			<?php if (!empty($movie['Keyword'])):?>
			<table cellpadding = "0" cellspacing = "0">
			<tr>
				<th><?php echo __('Title'); ?></th>
				<th><?php echo __('Duration'); ?></th>
				<th class="actions"><?php echo __('Actions');?></th>
			</tr>
			<?php
				$i = 0;
				$movies=$this->requestAction( array('controller' => 'movies', 'action' => 'searchRelated'),
											  array('keyword' => array($movie['Keyword']),
													'movie'=>array($movie['Movie']['title'])));
				foreach ($movies as $related): ?>
				<tr>
					<td><?php echo $related['Movie']['title'];?></td>
					<td><?php echo $related['Movie']['duration'].' min'; ?></td>
					<td class="actions">
						<?php echo $this->Html->link(__('View'), array('controller' => 'movies', 'action' => 'view', $related['Movie']['id'])); ?>
						<?php echo $this->Html->link(__('Edit'), array('controller' => 'movies', 'action' => 'edit', $related['Movie']['id'])); ?>
						<?php echo $this->Form->postLink(__('Delete'), array('controller' => 'movies', 'action' => 'delete', $related['Movie']['id']), null, __('Are you sure you want to delete # %s?', $related['Movie']['id'])); ?>
					</td>
				</tr>
			<?php endforeach; ?>
			</table>
		<?php endif; ?>
		</div>
		<div class="related">
			<h3><?php echo __('Related Movies from Web Service');?></h3>
			<?php if (!empty($movie['Movie'])):?>
			<table cellpadding = "0" cellspacing = "0">
			<tr>
				<th><?php echo __('Title'); ?></th>
				<th><?php echo __('Director'); ?></th>
				<th><?php echo __('Duration'); ?></th>
				<th><?php echo __('Release'); ?></th>
			</tr>
			
			<?php
				$i = 0;
				$movies=$this->requestAction( array('controller' => 'movies', 'action' => 'searchWebService'),
											  array('title' => array($movie['Movie']['title'])));
				foreach ($movies as $related): ?>
				<tr>
					<td><a href=<?php echo $related['url'];?>><?php echo $related['name'];?></a></td>
					<td><?php echo $related['director'];?></td>
					<td><?php echo $related['duration'];?></td>
					<td><?php echo $related['date'];?></td>
					<td></td>
				</tr>
			<?php endforeach; ?>
			</table>
		<?php endif; ?>
		</div>
	</body>
</html>